/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rtsgame.core.view.graphics;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;

/**
 *
 * @author tom
 */
public class ShapeElement extends GraphicElement {

  private Rectangle rect;
  private Color color;

  public ShapeElement( Rectangle rect, Color color )
  {
    this.rect = rect;
    this.color = color;
  }

  @Override
  public void Draw(Graphics2D graphic2D) {
    //System.out.println( "draw: " + rect );
    graphic2D.setColor(color);
    graphic2D.fillRect(new Double( rect.getX()).intValue(), new Double( rect.getY() ).intValue(),
            new Double( rect.getWidth()).intValue(), new Double( rect.getHeight() ).intValue());

  }

  @Override
  public void DrawSelect(Graphics2D graphic2D) {
    graphic2D.setColor( Color.GREEN );
    graphic2D.drawRect( new Double( rect.getX() ).intValue() - 2 , new Double( rect.getY() ).intValue() - 2,
                        new Double( rect.getWidth() ).intValue() + 3, new Double( rect.getHeight() ).intValue()  + 3);
  }



  @Override
  public boolean isCollision(GraphicElement element) {

    if( element instanceof ShapeElement )
    {
      return false;
    }
    return false;

  }

  @Override
  public boolean hit(int x, int y) {
    if( x >= getX() && x <= (getX() + rect.getWidth() ) &&
        y >= getY() && y <= (getY() + rect.getHeight() )   )
      return true;

    return false;
  }



  public Color getColor() {
    return color;
  }

  public Rectangle2D getRect() {
    return rect;
  }

  @Override
  public int getX() {
    return new Double( rect.getX() ).intValue();
  }

  @Override
  public int getY() {
    return new Double( rect.getY() ).intValue();
  }

  @Override
  public void setX(int x) {
    rect.setRect( x, rect.getY(), rect.getWidth(), rect.getHeight());
  }

  @Override
  public void setY(int y) {
    rect.setRect(rect.getX(), y, rect.getWidth(), rect.getHeight());
  }



}
